package com.ai.client;

import com.ai.aif.msgframe.producer.mq.rocketmq.api.TransactionCheckListenerImpl;
import com.alibaba.rocketmq.client.exception.MQClientException;
import com.alibaba.rocketmq.client.producer.LocalTransactionExecuter;
import com.alibaba.rocketmq.client.producer.SendResult;
import com.alibaba.rocketmq.client.producer.TransactionCheckListener;
import com.alibaba.rocketmq.client.producer.TransactionMQProducer;
import com.alibaba.rocketmq.common.message.Message;

public class MfTxmessageClient {
	String clusterName ="cluster-2";
	String centerName="rocketCenter";
	private TransactionMQProducer producer = null;
	private TransactionCheckListener checkListener = new TransactionCheckListenerImpl();
	
	
	public MfTxmessageClient() throws MQClientException {
		if(producer==null){
			producer = new TransactionMQProducer(clusterName+centerName);
			producer.setNamesrvAddr("10.19.9.25:9876");
			producer.setInstanceName(centerName + "_" + System.currentTimeMillis());
			producer.setTransactionCheckListener(checkListener);
			producer.start();
		}
	}

	public  SendResult send(Message msg,LocalTransactionExecuter executor ) throws MQClientException{
		SendResult sr = producer.sendMessageInTransaction(msg, executor, null);
		return sr;
	}
	

}
